package com.elink.enginerring.file.service;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.elink.enginerring.common.ErrorType;
import com.elink.enginerring.type.dao.TypeMapper;
import com.elink.enginerring.type.entity.Type;
import com.elink.enginerring.util.JSONUtil;

@Service
public class TypeService  implements ITypeService{
	@Autowired
	private TypeMapper typeMapper;

	@Override
	public Map<String, Object> getList() {
		return JSONUtil.getJSON(ErrorType.SUCCESS,typeMapper.getList());
	}

	@Override
	public void add(Type type) {
		type.setSequence(typeMapper.getMaxSeq());
		typeMapper.insertSelective(type);		
	}

	@Override
	public void modify(Type type) {
		typeMapper.updateByPrimaryKeySelective(type);
	}

	@Override
	public void del(String ids) {
		typeMapper.del(ids);
	}

	@Override
	public Map<String, Object> order(String id_seq) {
		for (String str : id_seq.split(",")) {
			typeMapper.order(str.split("_")[0], str.split("_")[1]);
		}
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}
}
